package com.magnificent.panda.model.generator.flow;

import java.util.ArrayList;
import java.util.Random;

/**
 * User: Babanin
 * Date: 21.09.2009
 * Time: 22:12:20
 */
public class VibrationFlow extends AbstractFlow {
    private Random rand = new Random(/*new Date().getTime()*/);

    private int len;//РґР»РёРЅРЅР° РјР°СЃСЃРёРІР° - РєРѕР»РёС‡РµСЃС‚РІРѕ РѕС‚СЃС‡РµС‚РѕРІ РїРѕС‚РѕРєР°
    private double intensity;//РёРЅС‚РµРЅСЃРёРІРЅРѕСЃС‚СЊ
    private int modelTime;
    private ArrayList<Double> exitX;
    private double samplingInterval;
    private double[] innerVector;

    public VibrationFlow(int intensity1, int intensity2, int modellingTime) {
        super(intensity1, intensity2, modellingTime);

        this.len = (int) intensity1 * modellingTime ;
        this.intensity = modellingTime / intensity1;        
        this.modelTime = modellingTime;
        this.samplingInterval = intensity;
    }

    public double getPeriod() {
        double period = 0;
        for (int i = 0; i < innerVector.length - 1; i++) {
            period = period + (innerVector[i + 1] - innerVector[i]);
        }
        period = period / (innerVector.length - 1);
        return period;
    }

    public double[] generate() {
        exitX = new ArrayList<Double>();
        exitX.add(Double.valueOf(0));
        double eps;
        int i = 1;
        while (exitX.get(exitX.size() - 1) <= modelTime) {
            eps = rand.nextDouble() * samplingInterval - (double) samplingInterval / 2;
            exitX.add(i * samplingInterval + eps);
            i = i + 1;
        }
        Double exitArray[] = new Double[exitX.size()];
        exitArray = exitX.toArray(exitArray);
        double exArray[] = new double[exitArray.length];
        for (int v = 0; v < exitArray.length; v++) {
            exArray[v] = exitArray[v];
        }
        innerVector = exArray;
        return exArray;
    }


}

  /* converted to utf8 */